/**********************************************************
 * UserAccountsDelegator.java
 * Created by ankur
 * Last modified Date: Aug 5, 2008 11:43:01 AM by ankur
 * Version : 0.1
 * Copyright (c) 2008 - 2008 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.delegator;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.printeverywhere.dto.PendingAccounts;
import com.printeverywhere.dto.UserAccountsCount;
import com.printeverywhere.util.HibernateUtil;
import static com.printeverywhere.util.LoggerConstants.*;

/**
 * The Class UserAccountsDelegator.
 */

public class UserAccountsDelegator {

	/** The Constant log. */
	private static final Log log = LogFactory.getLog(UserAccountsDelegator.class);

	/**
	 * Find all.
	 *
	 * @return the user accounts count
	 */
	@SuppressWarnings("unchecked")
	public static UserAccountsCount findAll() {
		if(log.isDebugEnabled())
		log.debug(USERACCOUNTSCOUNTALL);
		try {
			List<UserAccountsCount> list = HibernateUtil.getSession().createCriteria(UserAccountsCount.class).list();
			if(list.size()>0){
				return list.get(0);
			}
			else
			return null;
		} catch (RuntimeException re) {
			log.error(FIND_ALL_FAIL, re);
			throw re;
		}
	}

	public static PendingAccounts findPendingAccounts() {
		if(log.isDebugEnabled())
		log.debug("Method findPendingAccounts called ");
		try {
			List<PendingAccounts> list = HibernateUtil.getSession().createCriteria(PendingAccounts.class).list();
			if(list.size()>0){
				return list.get(0);
			}
			else
			return null;
		} catch (RuntimeException re) {
			log.error("Error while findPendingAccounts called", re);
			throw re;
		}
	}

}